package com.atbun.eduservice.controller.front;

import com.atbun.eduservice.entity.EduCourse;
import com.atbun.eduservice.entity.EduTeacher;
import com.atbun.eduservice.service.EduCourseService;
import com.atbun.eduservice.service.EduTeacherService;
import com.atbun.commonutils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description : 客户端的课程与讲师
 * @Author : mayp
 * @Date: 2020-05-13 22:22
 */
@RestController
@RequestMapping("/eduservice/indexFront")
public class IndexFrontController {

//    课程
    @Autowired
    private EduCourseService eduCourseService;
//    讲师
    @Autowired
    private EduTeacherService eduTeacherService;

    /**
     * 查询前8条热门课程,查询前4条讲师
     */
    @GetMapping("index")
    public R index(){

        QueryWrapper<EduCourse> courseWrapper = new QueryWrapper<>();
        courseWrapper.orderByDesc("id");
//        last方法，拼接sql语句
        courseWrapper.last("limit 8");
        List<EduCourse> courseList = this.eduCourseService.list(courseWrapper);

        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 8");
        List<EduTeacher> teacherList = this.eduTeacherService.list(teacherWrapper);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }

}
